/*
 * Based on jQuery Bookmarklet by Brett Barros and Paul Irish. More info here: http://crum.bs/l/e3
 * 
 * Copyright (c) 2010 Latent Motion (http://crum.bs/l/e3)
 * Released under the Creative Commons Attribution 3.0 Unported License,
 * as defined here: http://crum.bs/l/e5
 * 
 * Copyright (c) 2010 crum.bs (http://crum.bs/)
 * Released under the Creative Commons Attribution 3.0 Unported License,
 * as defined here: http://crum.bs/l/e5
 */
 
window.bookmarklet = function(opts){fullFunc(opts)};
 
// These are the styles, scripts and callbacks we include in our bookmarklet:
window.bookmarklet({
 
    css : [],
    js  : [],
    ready : function(){
 
		var url = document.location.href;
		var desc = document.title;
		//insert the bookmarklet
		$("<style type='text/css'>.crumbs_body { overflow: visible; font: Arial,Helvetica,sans-serif; font-size:small; outline:medium none; text-decoration:none; font-weight:normal; font-style:normal; background: url('http://iddhis.com/site_media/images/IDDHIS-big.png') no-repeat #9BB9C3; margin: 0; padding: 0; opacity: 0.25; color: #426069; z-index: 999999999; position: fixed; top: 0; right: 0; width: 210px; -moz-box-shadow: 0 0 15px #333; -webkit-box-shadow: 0 0 15px #333; box-shadow: 0 0 15px #333; }.crumbs_body form { padding: 0; margin: 65px 2px 0 0; }.crumbs_body p { text-align:left; line-height:1.5; margin: 0 auto; width: 200px; position: relative; display: block;}.crumbs_body span { display: inline; margin: 0 2px 0 2px; }.crumbs_body input { color: #C0B699; background: #fff; border: 1px solid #848C87; height: 18px; padding: 0; margin: 2px; width: 150px; }.crumbs_submit { background: #FAEED3 !important; border: 1px solid #F8EAB8 !important; color: #685F53 !important; width: 100%; Height: 20px; margin: 2px 2px 5px 2px; }.crumbs_close { position: absolute; top: 2px; right: 2px; height: 14px; width: 14px; background-image: url('http://crum.bs/bookmarklets/adv/cl.png'); }.crumbs_terms_field { text-align: center; }.crumbs_terms_field input { width: auto; height: auto; padding: 0; margin: 0; }</style>").appendTo('head');
		$("<div style='display:none;'class='crumbs_body'><a href='javascript:void(null);' class='crumbs_close'></a><form method='post' action='http://www.iddhis.com/sharing/save?status_text=I am browsing "+ escape(url) +"'><p><span>Web URL: <input type='text' name='url' value='"+url+"' /></span><span>Description: <input type='text' name='desc' value='"+desc+"' /></span><span>Custom Name: <input type='text' name='custom' value='' /></span></p><p><span>Password: <input type='password' name='password' value='' /></span></p><p><span>Limit (leave blank for unlimited): <input type='text' name='limit' value='' /></span></p><p><span class='crumbs_terms_field'><input type='checkbox' name='terms' /> I agree to all of crum.bs terms and conditions.</span></p><input name='submit' type='submit' class='crumbs_submit'value='Shorten' /></form></div>").appendTo('body');
		var height = $('.crumbs_body').outerHeight();
		$('.crumbs_body').css("top","-"+height).show().animate({
				opacity: 1,
				top: '0',
			}, 1000);
		
		$('.crumbs_close').click(function(){
			$('.crumbs_body').animate({
				opacity: 0.25,
				right: '-=250',
			  }, 1000, function() {
				$('.crumbs_body').remove();
			});
			
		});
	}
 
})
 
function fullFunc(opts){
 
    // User doesn't have to set jquery, we have a default.
    opts.jqpath = opts.jqpath || "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
 
    function getJS(jsfiles){
 
	// Check if we've processed all of the JS files (or if there are none)
	if (jsfiles.length === 0) {
		opts.ready();
		return false;
	}
 
        // Load the first js file in the array
        $.getScript(jsfiles[0],  function(){ 
 
            // When it's done loading, remove it from the queue and call the function again    
            getJS(jsfiles.slice(1));
 
        })
 
    }
 
    // Synchronous loop for css files
    function getCSS(csfiles){
        $.each(csfiles, function(i, val){
            $('<link>').attr({
                    href: val,
                    rel: 'stylesheet'
                }).appendTo('head');
        });
    }
 
	function getjQuery(filename) {
 
		// Create jQuery script element
		var fileref = document.createElement('script')
		fileref.type = 'text/javascript';
		fileref.src =  filename;
 
		// Once loaded, trigger other scripts and styles
		fileref.onload = function(){
 
			getCSS(opts.css); // load CSS files
			getJS(opts.js); // load JS files
 
		};
 
		document.body.appendChild(fileref);
	}
 
	getjQuery(opts.jqpath); // kick it off
 
}; // end of bookmarklet();
